package com.lzy.huijinjiazu.mvp.ui.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.di.component.DaggerOrderListComponent;
import com.lzy.huijinjiazu.di.module.OrderListModule;
import com.lzy.huijinjiazu.mvp.contract.OrderListContract;
import com.lzy.huijinjiazu.mvp.presenter.OrderListPresenter;
import com.lzy.huijinjiazu.mvp.ui.adapter.OrderAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


public class OrderListFragment extends BaseFragment<OrderListPresenter> implements OrderListContract.View {

    @BindView(R.id.rv_list)
    RecyclerView mRvList;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout mRefreshLayout;
    private String mStateType;
    private OrderAdapter mAdapter;

    public static OrderListFragment newInstance(String type) {
        OrderListFragment fragment = new OrderListFragment();
        Bundle bundle = new Bundle();
        bundle.putString("TYPE", type);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {
        DaggerOrderListComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .orderListModule(new OrderListModule(this))
                .build()
                .inject(this);
    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_order_list, container, false);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        if (bundle != null) {
            mStateType = bundle.getString("TYPE");
        }
        initRecyclerView();
        initData();
    }

    private void initRecyclerView() {
        ArmsUtils.configRecyclerView(mRvList, new LinearLayoutManager(getContext()));
        mAdapter = new OrderAdapter();
        mRvList.setAdapter(mAdapter);
    }

    private void initData() {
        List<String> data = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            data.add("");
        }
        mAdapter.addAll(data, true);
    }

}

